package com.zyf.school.manager.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zyf.school.manager.domain.Area;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

@Mapper
@Component(value = "areaDao")
public interface AreaDao extends BaseMapper<Area> {
    //插入数据
    /*@Insert("insert into area(tel,code,name,state,begintime,endtime,parent_id) values(#{tel},#{code},#{name},#{state},#{begintime},#{endtime},#{parentId})")
    void insert(Area area);*/

    //查询数据
    @Select("select * from area where tel = #{tel}")
    List<Area> queryByTel(String tel);

    //查询数据
    @Select("select b.* from area a,area b where a.parent_tel is null or a.parent_tel = #{tel} and a.tel = b.parent_tel")
    @Results({
            @Result(id=true,column = "tel",property = "tel"),
            @Result(column = "code",property = "code"),
            @Result(column = "name",property = "name"),
            @Result(column = "state",property = "state"),
            @Result(column = "begintime",property = "begintime"),
            @Result(column = "endtime",property = "endtime"),
            @Result(column = "parent_tel",property = "parentId")
    })
    List<Area> queryByParentTel(String tel);

    /*@Insert("insert into area(tel,code,name,state,begintime,endtime,parentid,login) value")
    public void save(Area area);*/
    @Select("select * from area where parent_tel = #{parentTel}")
    List<Area> queryChidren(String parentTel);
}
